import React, { Component } from 'react'
import { Toast } from 'antd-mobile';
export default class ProductItem extends Component {
  render() {
    let { item, index, list } = this.props;
    return (
      <li key={index}>

        <img src={item.img} alt="" />
        <p>{item.title}</p>
        <p>
          {item.price}
        </p>
        <div>




          <button onClick={() => {
            if (item.num > 0) {
              item.num--;
            }

            if (item.num === 0) {
              Toast.info('从购物车移除', 1);
            }

            this.props.setList(list);

          }} style={{ display: item.num ? 'inline' : 'none' }}>-</button>
          <span style={{ display: item.num ? 'inline' : 'none' }}>{item.num}</span>
          <button onClick={() => {
            item.num++;
            if (item.num === 1) {
              Toast.info('加入到购物车', 1);
            }
            this.props.setList(list);

          }}>+</button>
        </div>


      </li>
    )
  }
}

